# Copyright (c) 2013-2020, The Linux Foundation. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above
#       copyright notice, this list of conditions and the following
#       disclaimer in the documentation and/or other materials provided
#       with the distribution.
#     * Neither the name of The Linux Foundation nor the names of its
#       contributors may be used to endorse or promote products derived
#       from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
# ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#

on early-init
    write /proc/sys/kernel/sched_boost 1

on init
    write /dev/stune/foreground/schedtune.sched_boost_no_override 1
    write /dev/stune/top-app/schedtune.sched_boost_no_override 1
    write /dev/stune/schedtune.colocate 0
    write /dev/stune/background/schedtune.colocate 0
    write /dev/stune/system-background/schedtune.colocate 0
    write /dev/stune/foreground/schedtune.colocate 0
    write /dev/stune/top-app/schedtune.colocate 1
    write /sys/module/qpnp_rtc/parameters/poweron_alarm 1
    wait /dev/block/platform/soc/1d84000.ufshc
    symlink /dev/block/platform/soc/1d84000.ufshc /dev/block/bootdevice

    #change owner of white led
    chown system system /sys/class/leds/white/brightness
    chown system system /sys/class/leds/white/breath

    # Add a cpuset for the camera daemon
    # We want all cores for camera
    mkdir /dev/cpuset/camera-daemon
    write /dev/cpuset/camera-daemon/cpus 0-7
    write /dev/cpuset/camera-daemon/mems 0
    chown cameraserver cameraserver /dev/cpuset/camera-daemon
    chown cameraserver cameraserver /dev/cpuset/camera-daemon/tasks
    chmod 0660 /dev/cpuset/camera-daemon/tasks

    # ZRAM parameters
    write /sys/block/zram0/comp_algorithm lz4
    write /proc/sys/vm/page-cluster 0

on init && property:ro.boot.hwc=GLOBAL
    setprop ro.boot.product.hardware.sku vayu

on property:ro.boot.product.hardware.sku=vayu
    enable vendor.nfc_hal_service

on early-fs
    start vold

on fs
    start hwservicemanager
    mount_all /vendor/etc/fstab.qcom --early
    chown root system /mnt/vendor/persist
    chmod 0771 /mnt/vendor/persist
    restorecon_recursive /mnt/vendor/persist
    mkdir /mnt/vendor/persist/data 0700 system system
    mkdir /mnt/vendor/persist/audio 0755 system system
    chmod 644 /mnt/vendor/persist/audio/us_manual_cal
    #+ add for watermark
    mkdir /mnt/vendor/persist/camera 0777 root root
    mkdir /dev/logfs 0771 system system
    mount vfat /dev/block/bootdevice/by-name/logfs /dev/logfs noatime umask=006,uid=1000,gid=1000
    chown system system /dev/tiload_node
    chmod 660 /dev/tiload_node

    mkdir /mnt/vendor/persist/subsys 0770 root system

on post-fs
    # set RLIMIT_MEMLOCK to 64MB
    setrlimit 8 67108864 67108864

    start vendor.spdaemon
    start vendor.sec_nvm

on late-fs
    wait_for_prop hwservicemanager.ready true
    exec_start wait_for_keymaster
    mount_all /vendor/etc/fstab.qcom --late

on post-fs-data
    mkdir /vendor/data/tombstones 0771 system system
    mkdir /tombstones/modem 0771 system system
    mkdir /tombstones/lpass 0771 system system
    mkdir /tombstones/wcnss 0771 system system
    mkdir /tombstones/dsps 0771 system system
    mkdir /data/vendor/hbtp 0750 system system
    mkdir /data/vendor/nnhal 0700 system system
    mkdir /data/vendor/misc/display 0771 system system
    mkdir /data/vendor/nfc 0770 nfc nfc

    mkdir /data/vendor/thermal 0771 root system
    mkdir /data/vendor/thermal/config 0771 root system

    chown system system /dev/tfa_reg
    chown system system /dev/tfa_rw
    chown system system /dev/tfa_rpc
    chown system system /dev/tfa_control
    chmod 0660 /dev/tfa_reg
    chmod 0660 /dev/tfa_rw
    chmod 0660 /dev/tfa_rpc
    chmod 0660 /dev/tfa_control

on property:ro.boot.dp=0x0
    write /sys/bus/platform/devices/c440000.qcom,spmi:qcom,pm8150@0:qcom,power-on@800/pshold_reboot 7

on early-boot
    start vendor.sensors

on boot
    chown system system /sys/kernel/hbtp/display_pwr
    chown system system /sys/kernel/qvr_external_sensor/fd
    chown system system /sys/class/drm/card0-DSI-1/doze_backlight
    start rmt_storage
    start rfs_access
    write /dev/cpuset/top-app/cpus 0-3
    write /dev/cpuset/audio-app/cpus 1-2
    write /dev/cpuset/foreground/cpus 0-3
    write /dev/cpuset/foreground/boost/cpus 0-3
    write /dev/cpuset/background/cpus 0-3
    write /dev/cpuset/system-background/cpus 0-3
    write /dev/cpuset/top-app/cpus 0-7
    write /dev/cpuset/foreground/cpus 0-7
    write /dev/cpuset/foreground/boost/cpus 0-7
    write /dev/cpuset/background/cpus 0-7
    write /dev/cpuset/system-background/cpus 0-7

    # set default schedTune value for camera-daemon
    write /dev/stune/camera-daemon/schedtune.prefer_idle 1
    write /dev/stune/camera-daemon/schedtune.boost 0

    chown system system /sys/class/thermal/thermal_message/sconfig
    chown system system /sys/class/touch/touch_dev/palm_sensor

    chown system system /sys/class/backlight/panel0-backlight/brightness_clone
    chown system system /dev/lirc0
    chmod 0660 /dev/lirc0

    setprop vendor.usb.rndis.func.name "gsi"
    setprop vendor.usb.rmnet.func.name "gsi"
    setprop vendor.usb.rmnet.inst.name "rmnet"
    setprop vendor.usb.dpl.inst.name "dpl"
    setprop vendor.usb.qdss.inst.name "qdss"
    setprop vendor.usb.controller a600000.dwc3

    chmod 0660 /sys/touchpanel/double_tap
    chown system system /sys/touchpanel/double_tap

on boot && property:persist.vendor.usb.controller.default=*
    setprop vendor.usb.controller ${persist.vendor.usb.controller.default}

on property:sys.boot_completed=1
    rm /data/unencrypted/zram_swap
    swapon_all /vendor/etc/fstab.qcom
    write /proc/sys/vm/swappiness 100

service vendor.pd_mapper /vendor/bin/pd-mapper
    class core
    user system
    group system

service vendor.per_mgr /vendor/bin/pm-service
    class core
    user system
    group system
    ioprio rt 4

service vendor.per_proxy /vendor/bin/pm-proxy
    class core
    user system
    group system
    disabled

on charger
    mkdir /mnt/vendor/persist
    chown root system /mnt/vendor/persist
    chmod 0771 /mnt/vendor/persist
    mkdir /mnt/vendor/persist/subsys 0770 root system
    start vendor.power_off_alarm
    setprop sys.usb.controller a600000.dwc3
    setprop sys.usb.configfs 1
    chown system system /sys/class/leds/white/brightness
    write /sys/class/leds/white/brightness 255

service vendor.spdaemon /vendor/bin/spdaemon
    class core
    user system
    group system
    shutdown critical

service vendor.sec_nvm /vendor/bin/sec_nvm
    class core
    user system
    group system

service vendor.thermal-engine /vendor/bin/thermal-engine
   class main
   user root
   socket thermal-send-client stream 0666 system system
   socket thermal-recv-client stream 0660 system system
   socket thermal-recv-passive-client stream 0666 system system
   socket thermal-send-rule stream 0660 system system
   group root

service vendor.energy-awareness /vendor/bin/energy-awareness
    class main
    user system
    group system
    oneshot

service nv_mac /vendor/bin/nv_mac
    class late_start
    user system
    group system inet net_admin wifi net_raw
    oneshot

service dcvs-sh /vendor/bin/init.qti.dcvs.sh
    class late_start
    user root
    group root system
    disabled
    oneshot

on property:vendor.dcvs.prop=1
   start dcvs-sh

on property:vendor.audio.cit.spkcal.copy=true
    copy /data/vendor/cit/tas2557_cal.bin /mnt/vendor/persist/audio/tas2557_cal.bin
    copy /data/vendor/cit/tas2557_cal.txt /mnt/vendor/persist/audio/tas2557_cal.txt
    copy /data/vendor/cit/tas2557_chk.txt /mnt/vendor/persist/audio/tas2557_chk.txt
    chmod 666 /mnt/vendor/persist/audio/tas2557_cal.bin
    chmod 666 /mnt/vendor/persist/audio/tas2557_cal.txt
    chmod 666 /mnt/vendor/persist/audio/tas2557_chk.txt
    copy /data/vendor/cit/cs35l41_cal.bin /mnt/vendor/persist/audio/cs35l41_cal.bin
    copy /data/vendor/cit/cs35l41_cal.txt /mnt/vendor/persist/audio/cs35l41_cal.txt
    chmod 666 /mnt/vendor/persist/audio/cs35l41_cal.bin
    chmod 666 /mnt/vendor/persist/audio/cs35l41_cal.txt
    copy /data/vendor/cit/tfa9894_chk.txt /mnt/vendor/persist/audio/tfa9894_chk.txt
    chmod 666 /mnt/vendor/persist/audio/tfa9894_chk.txt
    copy /data/vendor/cit/tas25xx_calib.bin /mnt/vendor/persist/audio/tas25xx_calib.bin
    copy /data/vendor/cit/tas2559_cal.txt /mnt/vendor/persist/audio/tas2559_cal.txt
    chmod 666 /mnt/vendor/persist/audio/tas25xx_calib.bin
    chmod 666 /mnt/vendor/persist/audio/tas2559_cal.txt

service remosaic_daemon /system/vendor/bin/remosaic_daemon
   class late_start
   user camera
   group camera

service vendor.nfc_hal_service /vendor/bin/hw/android.hardware.nfc@1.2-service
    override
    class hal
    user nfc
    group nfc
    writepid /dev/cpuset/system-background/tasks
    disabled
